/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.zavgame.ejb;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 * Player entity class to store the instance in a storage.
 * 
 * @author alexey
 *
 */
@Entity
@NamedQueries({
   @NamedQuery(name = "player.query", query = "SELECT p FROM Player p WHERE p.username LIKE :username ORDER BY p.id DESC"),
   @NamedQuery(name = "player.all", query = "SELECT p FROM Player p ORDER BY p.id ASC")})
public class Player implements Serializable
{

   /**
    * 
    */
   private static final long serialVersionUID = 6090142216927571405L;

   @Id
   @GeneratedValue
   private long id;

   private String username;

   private int balanceVersion;

   private int balance;

   /**
    * Default constructor.
    */
   public Player()
   {
   }

   /**
    * Parameterized constructor to use in on client instance creation.
    * 
    * @param username
    * @param balanceVersion
    * @param balance
    */
   public Player(String username, int balanceVersion, int balance)
   {
      this.username = username;
      this.balanceVersion = balanceVersion;
      this.balance = balance;
   }

   public long getId()
   {
      return id;
   }

   public void setId(long id)
   {
      this.id = id;
   }

   public String getUsername()
   {
      return username;
   }

   public void setUsername(String username)
   {
      this.username = username;
   }

   public int getBalanceVersion()
   {
      return balanceVersion;
   }

   public void setBalanceVersion(int balanceVersion)
   {
      this.balanceVersion = balanceVersion;
   }

   public int getBalance()
   {
      return balance;
   }

   public void setBalance(int balance)
   {
      this.balance = balance;
   }

   @Override
   public String toString()
   {
      StringBuilder sb = new StringBuilder();
      sb.append("Player:{")//
         .append("id: ").append(id).append(" ") //
         .append(", username: ").append(username).append(" ") //
         .append(", balanceVersion: ").append(balanceVersion).append(" ") //
         .append(", balance: ").append(balance).append(" ") //
         .append("} ");
      return sb.toString();
   }

}
